package wps

import (
	"github.com/zzl/go-com/com"
	"github.com/zzl/go-com/ole"
	"github.com/zzl/go-win32api/v2/win32"
	"syscall"
)

// 45541089-5750-5300-4B49-4E47534F4655
var IID_Solver = syscall.GUID{0x45541089, 0x5750, 0x5300,
	[8]byte{0x4B, 0x49, 0x4E, 0x47, 0x53, 0x4F, 0x46, 0x55}}

type Solver struct {
	ole.OleClient
}

func NewSolver(pDisp *win32.IDispatch, addRef bool, scoped bool) *Solver {
	if pDisp == nil {
		return nil
	}
	p := &Solver{ole.OleClient{pDisp}}
	if addRef {
		pDisp.AddRef()
	}
	if scoped {
		com.AddToScope(p)
	}
	return p
}

func SolverFromVar(v ole.Variant) *Solver {
	return NewSolver(v.IDispatch(), false, false)
}

func (this *Solver) IID() *syscall.GUID {
	return &IID_Solver
}

func (this *Solver) GetIDispatch(addRef bool) *win32.IDispatch {
	if addRef {
		this.AddRef()
	}
	return this.IDispatch
}

var Solver_SolverAdd_OptArgs = []string{
	"FormulaText",
}

func (this *Solver) SolverAdd(cellRef interface{}, relation int32, optArgs ...interface{}) int32 {
	optArgs = ole.ProcessOptArgs(Solver_SolverAdd_OptArgs, optArgs)
	retVal, _ := this.Call(0x07a12000, []interface{}{cellRef, relation}, optArgs...)
	return retVal.LValVal()
}

var Solver_SolverChange_OptArgs = []string{
	"FormulaText",
}

func (this *Solver) SolverChange(cellRef interface{}, relation int32, optArgs ...interface{}) int32 {
	optArgs = ole.ProcessOptArgs(Solver_SolverChange_OptArgs, optArgs)
	retVal, _ := this.Call(0x07a12001, []interface{}{cellRef, relation}, optArgs...)
	return retVal.LValVal()
}

var Solver_SolverDelete_OptArgs = []string{
	"FormulaText",
}

func (this *Solver) SolverDelete(cellRef interface{}, relation int32, optArgs ...interface{}) int32 {
	optArgs = ole.ProcessOptArgs(Solver_SolverDelete_OptArgs, optArgs)
	retVal, _ := this.Call(0x07a12002, []interface{}{cellRef, relation}, optArgs...)
	return retVal.LValVal()
}

var Solver_SolverFinish_OptArgs = []string{
	"KeepFinal", "ReportArry", "OutlineReports",
}

func (this *Solver) SolverFinish(optArgs ...interface{}) int32 {
	optArgs = ole.ProcessOptArgs(Solver_SolverFinish_OptArgs, optArgs)
	retVal, _ := this.Call(0x07a12003, nil, optArgs...)
	return retVal.LValVal()
}

var Solver_SolverOk_OptArgs = []string{
	"SetCell", "MaxMinVal", "ValueOf", "ByChange",
	"Engine", "EngineDesc",
}

func (this *Solver) SolverOk(optArgs ...interface{}) int32 {
	optArgs = ole.ProcessOptArgs(Solver_SolverOk_OptArgs, optArgs)
	retVal, _ := this.Call(0x07a12007, nil, optArgs...)
	return retVal.LValVal()
}

var Solver_SolverOptions_OptArgs = []string{
	"MaxTime", "Iterations", "Precision", "AssumeLinear",
	"StepThru", "Estimates", "Derivatives", "SearchOption",
	"IntTolerance", "Scaling", "Convergence", "AssumeNonNeg",
	"PopulationSize", "randomSeed", "MultiStart", "RequireBounds",
	"MutationRate", "MaxSubproblems", "MaxIntegerSols", "SolveWithout", "MaxTimeNoImp",
}

func (this *Solver) SolverOptions(optArgs ...interface{}) int32 {
	optArgs = ole.ProcessOptArgs(Solver_SolverOptions_OptArgs, optArgs)
	retVal, _ := this.Call(0x07a12009, nil, optArgs...)
	return retVal.LValVal()
}

func (this *Solver) SolverReset() {
	retVal, _ := this.Call(0x07a1200a, nil)
	_ = retVal
}

var Solver_SolverSolve_OptArgs = []string{
	"UserFinish", "ShowRef",
}

func (this *Solver) SolverSolve(optArgs ...interface{}) int32 {
	optArgs = ole.ProcessOptArgs(Solver_SolverSolve_OptArgs, optArgs)
	retVal, _ := this.Call(0x07a1200c, nil, optArgs...)
	return retVal.LValVal()
}
